﻿using System;

namespace TK
{
    public partial class CustomSerializer
    {
        void writeGenericList(CustomSerializerState state, System.Collections.IList o, Type underlineType) {
            var objID = state.writeHeader();
            state.writeInt32(o.Count);
            writeSingleTypeCollection(state, o, underlineType);
            state.updateHeader(objID);
        }

        object readGenericList(CustomSerializerState state, Type type, Type ownerType, string propertyName)
        {
            var header = state.readHeader();
            var count = state.readInt32();
            var elementType = type.GetGenericArguments()[0];
            var list = createObject(type) as System.Collections.IList;
            
            for (var i = 0; i < count; i++) list.Add(getDefaultValue(elementType));
            readSingleTypeCollection(state, list, elementType, ownerType, propertyName);
            
            return list;
        }
    }
}